" 设置自动上翻下翻时光标预览行数
set scrolloff=3
" 使能backspace键删除功能
set backspace=2
" tab显示补全菜单
set wildmenu
"设置配色方案
colorscheme peachpuff
" 高亮显示搜索结果
set hlsearch

"设置语法高亮
syntax enable
syntax on

"高亮显示光标行
set cursorline

" 显示行尾的空格
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/"

"Tlist配置
let Tlist_Show_One_File=0
let Tlist_Exit_OnlyWindow=1

"winManger配置
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>

"cscope配置
:set cscopequickfix=s-,c-,d-,i-,t-,e-
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>

"QuickFix
nmap <F6> :cn<cr>
nmap <F7> :cp<cr>

"MiniBufExplorer配置
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1

"a配置
nnoremap <silent> <F12> :A<CR>

"grep配置
nnoremap <silent> <F3> :Grep<CR>

"代码自动补全
filetype plugin indent on
set completeopt=longest,menu
let g:SuperTabRetainCompletionType=2
let g:SuperTabDefaultCompletionType="<C-X><C-O>"

"设置显示行号
set nu

"设置普通模式指令回显
set showcmd

"设置自动缩进(ai) 设置tab宽度(tabstop=2)
"可以设置 autoindent smartindent cindent indentexpr
set smartindent

"设置tab键为2个字符长度
set tabstop=2
set shiftwidth=2
set expandtab
set softtabstop=2

" 可以在buffer的任何地方使用鼠标
set mouse=a

"设在tags
set tags=tags
nnoremap <F4> :!ctags -R<CR> :set tags=tags<CR>

" 插入匹配括号
inoremap ' ''<LEFT>
inoremap " ""<LEFT>
inoremap < <><LEFT>
inoremap ( ()<LEFT>
inoremap [ []<LEFT>
inoremap { {}<LEFT>

"设置代码折叠  help-->foldmethod
"zi 打开关闭折叠
"zv 查看此行
"zm 关闭折叠
"zM 关闭所有
"zR 打开所有
"zc 折叠当前行
"zo 打开当前折叠
"zd 删除折叠
"zD 删除所有折叠
set nowrap
set foldenable
set foldmethod=syntax
"下面一行是设置用空格键打开关闭折叠
nnoremap <space> @=((foldclosed('.') < 0) ? 'zc' : 'zo')<CR>

" vim -b : edit binary using xxd-format!
" 设置vim自动使用十六进制打开*.bin文件
	augroup Binary
	  au!
	  au BufReadPre  *.bin let &bin=1
	  au BufReadPost *.bin if &bin | %!xxd
	  au BufReadPost *.bin set ft=xxd | endif
	  au BufWritePre *.bin if &bin | %!xxd -r
	  au BufWritePre *.bin endif
	  au BufWritePost *.bin if &bin | %!xxd
	  au BufWritePost *.bin set nomod | endif
	augroup END
" 设置编码
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,gb2312,gbk,gb18030,cp936

" 映射常用案件符合emacs习惯
nnoremap <C-a> 0
nnoremap <C-e> $
"<C-k>失效被注释掉 nnoremap <C-k> d$
nnoremap <C-x><C-s> :w<CR>
nnoremap <C-x><C-c> :wq!<CR>
nnoremap <C-x><C-f> :e<space>
nnoremap <C-c>n :bn<CR>
nnoremap <C-c>p :bp<CR>
nnoremap <C-x>o <C-w>w
nnoremap <C-x>k :bdelete<CR>:syntax<space>on<CR>
inoremap <C-g> <ESC>
nnoremap <C-g> <ESC>
cnoremap <C-g> <ESC>

"设置leader键
let mapleader = ";"
"下面一行是设置用";;"打开关闭折叠
nnoremap <leader>; @=((foldclosed('.') < 0) ? 'zc' : 'zo')<CR>
nnoremap <leader>o zR
nnoremap <leader>c zM
nnoremap <leader>w :w<CR>
"编辑.vimrc文件
nnoremap <leader>vi <ESC> :new ~/.vim/vimrc<CR>
"重载.vimrc文件
nnoremap <leader>vs <ESC> :source ~/.vim/vimrc<CR>
"编译当前文件夹中的build目录
nnoremap <F5> <ESC>:cd build<CR> :make<CR> :cw<CR> :cd ..<CR> :cope<CR>

"快速切换insert模式到normal模式
inoremap <leader>; <ESC>
cnoremap <leader>; <ESC>

inoremap <leader>9 (
inoremap <leader>0 )
inoremap <leader>- _
inoremap <leader>= +
inoremap <leader>w <ESC>:w<CR>

"快速切换到insert模式，并将光标移动到行尾部
nnoremap <leader>a <S-a>
"快速切换到insert模式，并将光标移动到行首部
nnoremap <leader>i <S-i>
"对当前行首增加一个<Tab>键

nnoremap <leader>g <S-g>
nnoremap <leader>q :q<CR>
nnoremap <leader>w :w<CR>
nnoremap <leader>wq :wq<CR>
nnoremap <leader>xa :xa<CR>

"c编程常用快捷键
"更新tags
nnoremap <leader>tag :!ctags -R<CR> :set tags=tags<CR>
"行缩进
nnoremap <leader>ff <ESC><S-i>//<ESC>
inoremap <leader>ff <ESC><S-i>//<ESC>
"重定义回车键
inoremap <leader>ee <CR>
nnoremap <leader>ee <CR>
"行缩进
nnoremap <leader>tt <ESC><S-i><Tab><ESC>
inoremap <leader>tt <ESC><S-i><Tab><ESC>
"到build目录下执行make指令然后返回
inoremap <leader>rr <ESC>:w<CR>:make<CR>:cw<CR>
nnoremap <leader>rr <ESC>:w<CR>:make<CR>:cw<CR>
inoremap <leader>rb <ESC>:w<CR>:cd build<CR>:make install<CR>:cw<CR>:cd ..<CR>
nnoremap <leader>rb <ESC>:w<CR>:cd build<CR>:make install<CR>:cw<CR>:cd ..<CR>
inoremap <leader>ra <ESC>:w<CR>:cd build-arm<CR> :make<CR> :cw<CR> :cd ..<CR>
nnoremap <leader>ra <ESC>:w<CR>:cd build-arm<CR> :make<CR> :cw<CR> :cd ..<CR>
